package com.kstech.mp3604.ui.customView

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View
import com.blankii.androidlibrary.exts.loge

/**
 * author: blankii
 * created on: 2025/4/11 15:08
 * description: xml 使用的时候必须设置width height 精准值
 */
class DmCar : View {
    private val TAG = "DmCar"

    private var mPaintBlack: Paint? = null
    private var mViewWidth: Float = 0f
    private var mViewHeight: Float = 0f

    constructor(mContext: Context) : this(mContext, null)
    constructor(mContext: Context, arrrs: AttributeSet?) : this(mContext, arrrs!!, 0)
    constructor(mContext: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
        mContext, attrs, defStyleAttr
    ) {
        init(mContext, attrs)
    }

    private fun init(mContext: Context, attrs: AttributeSet) {

        mPaintBlack = Paint()
        mPaintBlack!!.setColor(Color.BLACK)
        mPaintBlack!!.strokeWidth = 3f
        mPaintBlack!!.style = Paint.Style.STROKE
        mPaintBlack!!.isAntiAlias = true

    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        mViewWidth = MeasureSpec.getSize(widthMeasureSpec).toFloat()
        mViewHeight = MeasureSpec.getSize(heightMeasureSpec).toFloat()
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    /**
     * progress in 0..100
     */

    override fun onDraw(canvas: Canvas) {
        //吊装框架
        val path = Path()
        path.moveTo(0f, mViewHeight)
        path.lineTo(0f, 0f)
        path.lineTo(mViewWidth, 0f)
        path.lineTo(mViewWidth, mViewHeight)

        canvas.drawPath(path, mPaintBlack!!)
        canvas.rotate(40f)
//        path.moveTo()
//
//        //背景2
//        val rectF = RectF(22f, 22f, mViewWidth - 70f, mViewHeight - 22f)
//        canvas.drawRect(rectF, mPaint_white!!)
//
//        //进度条
//        val progressRect = RectF(23f, 23f, mProgressWidth, mViewHeight - 23f)
//        canvas.drawRect(progressRect, mPaint_progress!!);

        super.onDraw(canvas)
    }
}